using System;
using System.Collections;
using UnityEngine;
using InControl;


namespace InControl
{
	// This custom profile is enabled by adding it to the Custom Profiles list
	// on the InControlManager component, or you can attach it yourself like so:
	// InputManager.AttachDevice( new UnityInputDevice( "KeyboardAndMouseProfile" ) );
	//
	public class SteamControllerProfile : CustomInputDeviceProfile
	{
        public SteamControllerProfile()
		{
			Name = "Steam Controller";
            Meta = "Steam Controller";

			ButtonMappings = new[] {
				new InputControlMapping {
					Handle = "1",
					Target = InputControlType.Action1,
					Source = KeyCodeButton(KeyCode.Return)
				},
				new InputControlMapping {
					Handle = "2",
					Target = InputControlType.Action2,
					Source = KeyCodeButton(KeyCode.Space)
				},
				new InputControlMapping {
					Handle = "3",
					Target = InputControlType.Action3,
					Source = KeyCodeButton(KeyCode.PageUp)
				},
				new InputControlMapping {
					Handle = "4",
					Target = InputControlType.Action4,
					Source = KeyCodeButton( KeyCode.PageDown )
				},
				new InputControlMapping {
					Handle = "Left Bumper",
					Target = InputControlType.LeftBumper,
					// KeyCodeComboButton requires that all KeyCode params are down simultaneously.
					Source = KeyCodeButton( KeyCode.LeftControl )
				},
                new InputControlMapping {
					Handle = "Right Bumper",
					Target = InputControlType.RightBumper,
					// KeyCodeComboButton requires that all KeyCode params are down simultaneously.
					Source = KeyCodeComboButton( KeyCode.LeftAlt)
				},
                new InputControlMapping {
					Handle = "Left Trigger",
					Target = InputControlType.LeftTrigger,
					// KeyCodeComboButton requires that all KeyCode params are down simultaneously.
					Source = MouseButton1
				},
                new InputControlMapping {
					Handle = "Right Trigger",
					Target = InputControlType.RightTrigger,
					// KeyCodeComboButton requires that all KeyCode params are down simultaneously.
					Source = MouseButton0
				},
                new InputControlMapping {
                    Handle = "Left Stick Button",
                    Target = InputControlType.LeftStickButton,
                    Source = MouseButton2
                },
                 new InputControlMapping {
                    Handle = "Right Stick Button",
                    Target = InputControlType.RightStickButton,
                    Source = KeyCodeComboButton( KeyCode.LeftShift)
                },
                new InputControlMapping {
                    Handle = "B9",
                    Target = InputControlType.Select,
                    Source = KeyCodeComboButton(KeyCode.Tab)
                },
                new InputControlMapping {
                    Handle = "B10",
                    Target = InputControlType.Start,
                    Source = KeyCodeComboButton(KeyCode.Escape)
                },
                new InputControlMapping {
                    Handle = "B10",
                    Target = InputControlType.Back,
                    Source = KeyCodeComboButton(KeyCode.Tab)
                }
               
			};

			AnalogMappings = new[] {
				new InputControlMapping {
					Handle = "Move Up",
					Target = InputControlType.LeftStickUp,
					Source = KeyCodeButton( KeyCode.W, KeyCode.UpArrow )
				},
				new InputControlMapping {
					Handle = "Move Down",
					Target = InputControlType.LeftStickDown,
					Source = KeyCodeButton( KeyCode.S, KeyCode.DownArrow )
				},
				new InputControlMapping {
					Handle = "Move Left",
					Target = InputControlType.LeftStickUp,
					Source = KeyCodeButton( KeyCode.A, KeyCode.LeftArrow )
				},
				new InputControlMapping {
					Handle = "Move Right",
					Target = InputControlType.LeftStickDown,
					Source = KeyCodeButton( KeyCode.D, KeyCode.RightArrow )
				},
                new InputControlMapping {
                    Handle = "Look Up",
                    Target = InputControlType.RightStickUp,
                    Source = MouseYAxis,
                    SourceRange = InputRange.ZeroToPositiveInfinity,
                    Raw = true,
                    Scale = 0.1f
                },
                new InputControlMapping {
                    Handle = "Look Down",
                    Target = InputControlType.RightStickDown,
                    Source = MouseYAxis,
                    SourceRange = InputRange.ZeroToNegativeInfinity,
                    Raw = true,
                    Scale = 0.1f,
                    Invert = true
                },
                new InputControlMapping {
                    Handle = "Look Left",
                    Target = InputControlType.RightStickLeft,
                    Source = MouseXAxis,
                    SourceRange = InputRange.ZeroToNegativeInfinity,
                    Raw = true,
                    Scale = 0.1f,
                    Invert = true
                },
                new InputControlMapping {
                    Handle = "Look Right",
                    Target = InputControlType.RightStickRight,
                    Source = MouseXAxis,
                    SourceRange = InputRange.ZeroToPositiveInfinity,
                    Raw = true,
                    Scale = 0.1f
                },
                new InputControlMapping {
                    Handle = "Look Z",
                    Target = InputControlType.ScrollWheel,
                    Source = MouseScrollWheel,
                    SourceRange = InputRange.Everything,
                    Raw = true,
                    Scale = 0.1f
                }
			};
		}
	}
}

